
package ch.hearc.meteo.imp.afficheur.real;

import java.awt.BorderLayout;
import java.io.FileInputStream;
import java.util.Properties;

import ch.hearc.meteo.imp.afficheur.real.moo.StationMeteoElement;
import ch.hearc.meteo.imp.afficheur.real.vue.JPanelCentral;
import ch.hearc.meteo.imp.afficheur.real.vue.JPanelInformationsMeteo;
import ch.hearc.meteo.imp.afficheur.real.vue.JPanelLeft;
import ch.hearc.meteo.spec.reseau.MeteoServiceWrapper_I;
import ch.hearc.meteo.tools.ImageShop;

public class JFrameStationMeteoRemote extends JFrameStationMeteo
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	private JFrameStationMeteoRemote()
		{
		super();
		JDialogPreferencesRemote preferences = new JDialogPreferencesRemote();
		if (preferences.isOk() == false)
			{
			System.exit(0);
			}
		this.isLocal = false;

		loadPreferences();

		geometry();
		control();
		apparence();

		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	public static JFrameStationMeteo getInstance()
		{
		if (instance == null)
			{
			instance = new JFrameStationMeteoRemote();
			}

		return instance;
		}

	@Override
	public void refreshSelectedStations(StationMeteoElement stationMeteoElement)
		{
		this.panelCentral.getPanelInformationsMeteo().updatelisteStationMeteoSelectionnee(stationMeteoElement);
		}

	@Override
	public void addMeteoServiceWrapper(MeteoServiceWrapper_I meteoServiceWrapper, AfficheurService afficheurService)
		{
		panelCentral.addMarker(afficheurService.getStationMeteoElement().getPanelStationMeteoCarteElement());
		panelLeft.addStationMeteo(afficheurService.getStationMeteoElement().getPanelStationMeteoListElement());
		}

	@Override
	public void removeMeteoServiceWrapper(MeteoServiceWrapper_I meteoServiceWrapper_I, AfficheurService afficheurService)
		{
		panelCentral.removeMarker(afficheurService.getStationMeteoElement().getPanelStationMeteoCarteElement());
		panelLeft.removeStationMeteo(afficheurService.getStationMeteoElement().getPanelStationMeteoListElement());
		}

	/*------------------------------*\
	|*				Set				*|
	\*------------------------------*/

	/*------------------------------*\
	|*				Get				*|
	\*------------------------------*/

	@Override
	public JPanelCentral getPanelCentral()
		{
		return this.panelCentral;
		}

	@Override
	public JPanelInformationsMeteo getPanelInformationsMeteo()
		{
		return this.panelCentral.getPanelInformationsMeteo();
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	private void geometry()
		{
		this.setLayout(new BorderLayout());
		panelCentral = new JPanelCentral();
		panelLeft = new JPanelLeft();
		this.add(panelCentral, BorderLayout.CENTER);
		this.add(panelLeft, BorderLayout.WEST);

		}

	private void control()
		{
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);

		}

	private void apparence()
		{

		this.setExtendedState(MAXIMIZED_BOTH);
		this.setIconImage(ImageShop.ICON_REMOTE);
		this.setTitle("PC Central");
		this.setVisible(true);

		}

	private void loadPreferences()
		{

		try
			{
			Properties p = new Properties();
			p.load(new FileInputStream(JDialogPreferencesRemote.PROPERTY_FILENAME));
			String proxyAdress = p.getProperty(JDialogPreferencesRemote.PROXY_ADDRESS_PROPERTY_NAME);
			String proxyPort = p.getProperty(JDialogPreferencesRemote.PROXY_PORT_PROPERTY_NAME);
			Boolean proxyActive = Boolean.valueOf(p.getProperty(JDialogPreferencesRemote.PROXY_ACTIVATED_PROPERTY_NAME));
			if (proxyActive)
				{
				System.setProperty("http.proxyHost", proxyAdress);
				System.setProperty("http.proxyPort", proxyPort);
				}
			}
		catch (Exception e)
			{

			}
		}

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/

	private JPanelCentral panelCentral;

	}
